package com.woniuxy.micromemberserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.micromemberserver.bean.MemberTypeBean;
import com.woniuxy.micromemberserver.bean.PageRequest;
import com.woniuxy.micromemberserver.mapper.MemberTypeMapper;
import com.woniuxy.micromemberserver.service.IMemberTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Transactional(readOnly = true)
@Service
public class MemberTypeServiceImpl implements IMemberTypeService {

    @Resource
    private MemberTypeMapper memberTypeMapper;

    /**
     * 条件分页查询
     * @param request 分页请求
     * @param memberTypeBean 会员类型实体
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public PageInfo<MemberTypeBean> findAllByParams(PageRequest request, MemberTypeBean memberTypeBean) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).doSelectPageInfo(()->
                memberTypeMapper.findAllByParams(request,memberTypeBean)
        );
    }

    /**
     * 新增会员类型
     * @param memberTypeBean
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public int saveMemberType(MemberTypeBean memberTypeBean) {
        return memberTypeMapper.saveMemberType(memberTypeBean);
    }

    /**
     * 修改会员类型（或删除：仅修改删除标记）
     * @param memberTypeBean
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public int updateMemberType(MemberTypeBean memberTypeBean) {
        return memberTypeMapper.updateMemberType(memberTypeBean);
    }
}
